<template>
  <div>
    <!-- 招标公告 2018/2/19 11:43 zhangQ -->
    <Row>
      <i-col :span="24">
        <span>排序</span>
        <RadioGroup v-model="tabParam.type" type="button" style="margin-left: 20px;"
                    @on-change="handleSearchBidding">
          <Radio label="all">全部</Radio>
          <Radio label="effective">有效期内</Radio>
        </RadioGroup>

        <Form ref="tenderForm" :model="tenderForm" inline style="float: right;">
          <span class="lh-32">开始日期</span>
          <FormItem>
            <DatePicker format="yyyy年MM月dd日" v-model="tenderForm.startTime"
                        placeholder="选择日期" style="width: 200px"></DatePicker>
          </FormItem>
          <span class="lh-32">结束日期</span>
          <FormItem>
            <DatePicker format="yyyy年MM月dd日" v-model="tenderForm.endTime"
                        placeholder="选择日期" style="width: 200px"></DatePicker>
          </FormItem>
          <FormItem>
            <Button type="primary" @click="handleSearchBidding">查询</Button>
          </FormItem>
        </Form>
      </i-col>
    </Row>

    <tablePage ref="tenderTab" :api="getBiddingListByPage" :param="tabParam" >
      <template slot-scope="props">
        <Table :columns="tenderColumn" :data="props.data"></Table>
      </template>
    </tablePage>
  </div>
</template>
<script>
  import tablePage from '@components/table/tablePage.vue'
  import { getBiddingListByPage } from '@api/backEnd/productDemand'
  import moment from 'moment'

  export default {
    name: 'tenderMsg',
    data () {
      let tenderForm = {
        startTime: '',
        endTime: ''
      }
      let tabParam = {
        type: 'all',
        isMine: 0
      }
      let tenderColumn = [
        {
          title: '发布时间',
          align: 'center',
          key: 'publicTime',
          render: (h, params) => {
            let publicTime = params.row.publicTime
            return h('Poptip', {
              props: {
                content: publicTime,
                placement: 'top',
                trigger: 'hover'
              }
            }, publicTime)
          }
        },
        {
          title: '截止时间',
          align: 'center',
          key: 'endTime',
          render: (h, params) => {
            let endTime = params.row.endTime
            return h('Poptip', {
              props: {
                content: endTime,
                placement: 'top',
                trigger: 'hover'
              }
            }, endTime)
          }
        },
        {
          title: '项目名称',
          ellipsis: true,
          align: 'center',
          key: 'projectName',
          render: (h, params) => {
            let projectName = params.row.projectName
            return h('Poptip', {
              props: {
                content: projectName,
                placement: 'top',
                trigger: 'hover'
              }
            }, projectName)
          }
        },
        {
          title: '发布单位',
          ellipsis: true,
          align: 'center',
          key: 'publicCompany',
          render: (h, params) => {
            let publicCompany = params.row.publicCompany
            return h('Poptip', {
              props: {
                content: publicCompany,
                placement: 'top',
                trigger: 'hover'
              }
            }, publicCompany)
          }
        },
        {
          title: '联系人',
          align: 'center',
          key: 'people',
          render: (h, params) => {
            let people = params.row.people
            return h('Poptip', {
              props: {
                content: people,
                placement: 'top',
                trigger: 'hover'
              }
            }, people)
          }
        },
        {
          title: '联系电话',
          align: 'center',
          key: 'telephone',
          render: (h, params) => {
            let telephone = params.row.telephone
            return h('Poptip', {
              props: {
                content: telephone,
                placement: 'top',
                trigger: 'hover'
              }
            }, telephone)
          }
        }
      ]
      let datas = { tabParam, getBiddingListByPage, tenderColumn, tenderForm }
      return datas
    },
    methods: {
      handleSearchBidding () {
        let tabParamClone = Object.assign({}, this.tabParam)
        if (this.tenderForm.endTime && this.tenderForm.startTime) {
          tabParamClone.startTime = moment(this.tenderForm.startTime).format('YYYY-MM-DD HH:mm:ss')
          tabParamClone.endTime = moment(this.tenderForm.endTime).format('YYYY-MM-DD HH:mm:ss')
          if (tabParamClone.startTime > tabParamClone.endTime) {
            this.$Message.error('开始时间不得大于结束时间!')
            return
          }
        }
        this.$refs['tenderTab'].dataRefresh(tabParamClone)
      }
    },
    components: {
      tablePage
    }
  }
</script>
<style scoped>
  .lh-32 {
    line-height: 32px;
    margin-right: 5px;
  }
</style>
